
<%--
  Created by lirong
  Date: 2017/6/11
  Time: 1:22
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="dao.ItemsDAO" %>
<%@ page import="entity.Items" %>
<%@ page import="java.util.ArrayList" %>
<html>
<head>
    <title>商品详情</title>
    <link rel="stylesheet" href="css/css.css">
</head>
<body>


<div class="main">

    <div class="body-left">
        <%
            ItemsDAO itemsDAO =new ItemsDAO();
            Items items =itemsDAO.getItemsById(Integer.parseInt(request.getParameter("id")));
            if (items!=null){
        %>
        <div class="title"><%=items.getName()%></div>

        <div class="info">城市：<%=items.getCity()%>  价格：<%=items.getPrice()%>  数量：<%=items.getNumber()%></div>
        <div class="pic"><img src="images/<%=items.getPicture()%>" width="500" alt="<%=items.getName()%>"></div>
        <%
            }else {
        %>
        <div class="nodata">没有详情信息！</div>
        <%
            }
        %>
    </div>
    <%
        String list="";
        Cookie[] cookies =request.getCookies();
        for (Cookie c:cookies){
            if (c.getName().equals("ListViewCookie")){
                list =c.getValue();
            }
        }
        if (list.indexOf(request.getParameter("id").toString())==-1){
            list +=request.getParameter("id")+",";
            String[] arr =list.split(",");
            if (arr!=null && arr.length>0){
                if (arr.length>1000){
                    list ="";
                }
            }
            Cookie cookie =new Cookie("ListViewCookie",list);
            response.addCookie(cookie);
        }

    %>

    <div class="body-right">
        <div class="title">商品浏览记录</div>
        <%
           ArrayList<Items> itemsList =  itemsDAO.getViewList(list);
           if (itemsList!=null && itemsList.size()>0){
               for (Items i:itemsList){
        %>
        <div class="cookielist">
            <div class="pic"><img src="images/<%=i.getPicture()%>" alt="" width="180"></div>
            <div class="name">名称：<%=i.getName()%>  价格：<%=i.getPrice()%></div>
        </div>
        <%
            }
            }
        %>
    </div>



</div>

</body>
</html>
